home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Dots & Pixels
/
sources
/
outputfile.cp
< prev
next >
Wrap
Text File
|
1995-09-29
|
3KB
|
103 lines
#if defined( macintosh) || defined( __MWERKS__)
#include <Files.h>
#include <OSUtils.h>
#if defined( __SC__)
#include <pascal.h>
#endif
#include <Finder.h> // for kNameLocked
#else
#include <time.h>
#endif
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include "outputfile.h"
//
// set2chars is a quick hack which puts the ascii representation of the last two
// digits of the number passed in in the two characters pointed to by two_chars.
//
void outputfile::set2chars( const int n, char *two_chars)
{
const char lastdigit = n % 10;
const char firstdigit = ((n - lastdigit) / 10) % 10;
two_chars[ 0] = firstdigit + '0';
two_chars[ 1] = lastdigit + '0';
}
#if defined( macintosh) || defined( __MWERKS__)
void outputfile::setoutfilename( char *yymmdd_hhmmss_plus_postfix)
{
DateTimeRec now;
GetTime( &now);
set2chars( now.year, &yymmdd_hhmmss_plus_postfix[ 0]);
set2chars( now.month, &yymmdd_hhmmss_plus_postfix[ 2]);
set2chars( now.day, &yymmdd_hhmmss_plus_postfix[ 4]);
set2chars( now.hour, &yymmdd_hhmmss_plus_postfix[ 7]);
set2chars( now.minute, &yymmdd_hhmmss_plus_postfix[ 9]);
set2chars( now.second, &yymmdd_hhmmss_plus_postfix[ 11]);
}
#else
void outputfile::setoutfilename( char *yymmdd_hhmmss_plus_postfix)
{
const time_t now_in_seconds = time( NULL);
struct tm *now = localtime( &now_in_seconds);
set2chars( now->tm_year, &yymmdd_hhmmss_plus_postfix[ 0]);
set2chars( now->tm_mon, &yymmdd_hhmmss_plus_postfix[ 2]);
set2chars( now->tm_mday, &yymmdd_hhmmss_plus_postfix[ 4]);
set2chars( now->tm_hour, &yymmdd_hhmmss_plus_postfix[ 7]);
set2chars( now->tm_min, &yymmdd_hhmmss_plus_postfix[ 9]);
set2chars( now->tm_sec, &yymmdd_hhmmss_plus_postfix[ 11]);
}
#endif
#ifdef it_doesnt_work
outputfile::outputfile( char *postfix, Boolean name_locked)
#else
outputfile::outputfile( char *postfix, Boolean name_locked) : ofstream()
#endif
{
strcpy( filename, "yymmdd hhmmss ");
//
// This is sloppy programming (the 200 limit is to low), but certainly works
// and 200 bytes for a filename is long enough (certainly on a Mac)
//
strncat( filename, postfix, 200);
setoutfilename( filename);
#if defined( macintosh) || defined( __MWERKS__)
filename[ 31] = 0; // 940309: limit length of filename on Mac to 31
CtoPstr( filename);
(void)Create( (ConstStr255Param)filename, 0, 'R*ch', 'TEXT');
if( name_locked)
{
FInfo theInfo;
if( GetFInfo( (ConstStr255Param)filename, 0, &theInfo) == noErr)
{
theInfo.fdFlags &= ~kHasBeenInited;
theInfo.fdFlags |= kNameLocked;
(void)SetFInfo( (ConstStr255Param)filename, 0, &theInfo);
}
}
PtoCstr( (unsigned char *)filename);
#endif
#ifndef it_doesnt_work
#ifdef THINK_CPLUS
ofstream::open( filename, ios::app | ios::out | ios::translated);
#else
ofstream::open( filename, ios::app | ios::out);
#endif
#endif
}
char *outputfile::operator()() const
{
return (char *)filename;
}